<template>
  <!-- 交易历史 -->
  <div id="history">
    <div class="left-box">
      <div class="avatar" @click="$router.push('/user/'+user.user_address)">
        <img :src="user.logo | ipfsHash" alt="avatar" v-if="user.logo != null"/>
        <RandomAvatar :user_address='user.user_address' v-if="user.logo == null"/>
      </div>
      <div class="data-info">
        <div class="username" v-if="user.nickname!=null">由 {{user.nickname}} {{ data.info }}</div>
        <div class="username" v-if="user.nickname==null">由 {{user.user_address|filterAddress}} {{ data.info }}</div>
        <div class="time">{{ data.time*1000 | formatDate('yyyy-MM-dd hh:mm:ss') }}</div>
      </div>
    </div>
    <div class="right-box" v-if="data.totalPrice != null">
      <div class="price">{{ data.totalPrice | weiToEth }} ETH</div>
    </div>
  </div>
</template>

<script>
import {getOtherInformation} from '@/api'
export default {
  name: "History",
  props: ["data"],
  data(){
    return{
      user:{}
    }
  },
  mounted(){
    // 查询用户信息
    getOtherInformation(this.$store.getters.user_address, this.data.user_address).then(res=>{
      this.user = res[0]
    })
  }
};
</script>

<style lang='less' scope>
#history {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  padding: 20px 20px;
  border-radius: 20px;
  box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.05);
  .left-box {
    display: flex;
    align-items: center;
    .avatar {
      width: 40px;
      height: 40px;
      cursor: pointer;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .data-info {
      margin-left: 10px;
      font-size: 14px;
      .time {
        margin-top: 10px;
      }
    }
  }

  .right-box {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>